//function foo(x) {
//  var tmp = 3;
//  return function (y) {
//      alert(x + y + (++tmp));
//  }
//}
//var bar = foo(2); // bar 现在是一个闭包
////bar(10);
////bar = foo(2);
////bar(10);
//foo(2)(10)

////生成题意
//var arr = [], n = 10000;
//for (var i = 0; i < n; i++) {
//  arr.push(i + 1);
//}
//var num1 = arr.splice(Math.floor(Math.random() * arr.length), 1);
//var num2 = arr.splice(Math.floor(Math.random() * arr.length), 1);
//var num3 = arr.splice(Math.floor(Math.random() * arr.length), 1);
//document.write('随机抽掉的3个数是：' + num1 + ' 和 ' + num2 + ' 和 ' + num3 + '<br/><br/>'); 
//arr.sort(function(){return Math.random() > 0.6});
// 
////求b、c、d
//var t = new Date();
//var b = c = d = 0, l = arr.length;   // 设3个数的和、平方和、立方和分别为b、c、d       
//for (var i = 0; i < n; i ++) {
//  b += i + 1;
//  c += (i + 1) * (i + 1);   
//  d += (i + 1) * (i + 1) * (i + 1);                    
//  if (i < l) {
//      b -= arr[i];
//      c -= arr[i] * arr[i];  
//      d -= arr[i] * arr[i] * arr[i];                       
//  }
//}
//t = new Date() - t;
//document.write('3个数的和、平方和、立方和是：b='+b+'，'+'c='+c+ '，'+'d='+d+'，'+'共耗时：'+t+'毫秒<br/><br/>')
//if (!("a" in window)) {
//  var a = 1;
//}
//alert (a);

//var a = 1,
//  b = function a (x) {
//      x && a (--x);
//  };
//alert (a);
//
//function a (x) {
//  return x * 2;
//}
//var a;
//alert (a);
//function b (x, y, a) {
//  arguments[2] = 10;
//  alert (a);
//}
//b(1, 2, 3);
//
//
//function a () {
//  alert (this);
//}
//a.call (null);
//var polyline =  Polyline.CreateNew().Labelid("ceshi").CreateSvg();
//console.log(polyline);
//var polyline = Polyline.CreateNew().Labelid("ceshi").CreateSvg();
//console.log(polyline);

////  ========== 
////  = 1 = 
////  ========== 
//var piesceshi = Pies3D.CreateNew().Labelid("ceshi").CreateSvg();
//var data = CreateData();
//piesceshi.Sequence(1);
//piesceshi.Data(data).Ldraw();
////setInterval(yanshi,5000);
//window.i = 1;
// function yanshi () {
//	i % 3 == 0 ? piesceshi.Sequence(-1) : (i % 3 == 1 ? piesceshi.Sequence(1) : piesceshi.Sequence(0));
// piesceshi.Ldraw();
// i++;
//}
// function CreateData () {
//return [
////["平面类.邮品","5760"],
////["立体类.甲骨","4503"],
////["立体类.印章","11910"],
////["立体类.瓷器","11190"],
////["立体类.陶器","3422"],
////["立体类.钱币","39340"],
////["平面类.皮影","7618"],
////["立体类.青铜","6200"],
////["平面类.纸币","8298"],
////["平面类.绘画","7783"],
////["更多...","28882"]
//["平面类.邮品","0"],
//["立体类.甲骨","0"],
//["立体类.印章","0"],
//["立体类.瓷器","0"],
//["立体类.陶器","0"],
//["立体类.钱币","0"],
//["平面类.皮影","0"],
//["立体类.青铜","0"],
//["平面类.纸币","0"],
//["平面类.绘画","11110"]
////,
////["更多...","0"]
//]
//	
//}

//  ========== 
//  = 2 = 
//  ========== 
//d3.selectAll("#ceshi").append("svg");
//js
//var canvasjs = document.getElementById('js');
//canvasjs.width = $("body").width();
//canvasjs.height = 300;
//var ctx_js = canvasjs.getContext('2d');
////d3
//var canvasd3 = d3.selectAll("body").append("canvas")[0][0];
//canvasd3.width = $("body").width();
//canvasd3.height = 300;
//var ctx_d3 = canvasd3.getContext("2d");
////ctx_js
//	//绘制填充矩形
//	ctx_js.fillStyle = "green";
//ctx_js.fillRect(0, 0, 300, 300);
//	//绘制填充矩形
//	ctx_js.fillStyle = "black";
//ctx_js.fillRect(20, 20, 80, 80);
//	//绘制矩形的边框
//	ctx_js.strokeStyle = "red";
//ctx_js.strokeRect(120, 20, 80, 80);
//	//清除一个矩形区域
//ctx_js.clearRect(70, 20, 80, 82);
//
////ctx_d3
//	//绘制填充矩形
//	ctx_d3.fillStyle = "green";
//ctx_d3.fillRect(0, 0, 300, 300);
//	//绘制填充矩形
//	ctx_d3.fillStyle = "black";
//ctx_d3.fillRect(20, 20, 80, 80);
//	//绘制矩形的边框
//ctx_d3.strokeRect(120, 20, 80, 80);
//	//清除一个矩形区域
//ctx_d3.clearRect(70, 20, 80, 80);

//ctx_js.beginPath();
//ctx_js.moveTo(400,0);
//ctx_js.lineTo(500,300);
//ctx_js.lineTo(300,300);
//ctx_js.fill();
//
//ctx_d3.beginPath();
//ctx_d3.moveTo(400,0);
//ctx_d3.lineTo(500,300);
//ctx_d3.lineTo(300,300);
//ctx_d3.closePath();
//ctx_d3.stroke();
//
//
//ctx_js.beginPath();
//ctx_js.arc(550,150,120,0,Math.PI,false);
//ctx_js.fill();
//
//ctx_d3.beginPath();
//ctx_d3.arc(550,150,120,0,Math.PI,false);
//ctx_d3.stroke();
//
////var p = new Path2D("M10 10 h 80 v 80 h -80 Z");
////ctx_js.fill(p);
//
////for (var i=0;i<6;i++){
////    for (var j=0;j<6;j++){
////      ctx_d3.strokeStyle = 'rgb(0,' + Math.floor(255-42.5*i) + ',' + 
////                       Math.floor(255-42.5*j) + ')';
////      ctx_d3.beginPath();
////      ctx_d3.arc(12.5+j*25,12.5+i*25,10,0,Math.PI*2,true);
////      ctx_d3.stroke();
////    }
////  }
//
//ctx_js.fillStyle = '#FD0';
//ctx_js.fillRect(0,0,75,75);
//ctx_js.fillStyle = '#6C0';
//ctx_js.fillRect(75,0,75,75);
//ctx_js.fillStyle = '#09F';
//ctx_js.fillRect(0,75,75,75);
//ctx_js.fillStyle = '#F30';
//ctx_js.fillRect(75,75,75,75);
//ctx_js.fillStyle = '#FFF';
//
//// 设置透明度值
//ctx_js.globalAlpha = 0.2;
//
//// 画半透明圆
//for (var i=0;i<7;i++){
//    ctx_js.beginPath();
//    ctx_js.arc(75,75,10+10*i,0,Math.PI*2,true);
//    ctx_js.fill();
//}
//
//// 画背景
//ctx_d3.fillStyle = '#FD0';
//ctx_d3.fillRect(0,0,75,75);
//ctx_d3.fillStyle = '#6C0';
//ctx_d3.fillRect(75,0,75,75);
//ctx_d3.fillStyle = '#09F';
//ctx_d3.fillRect(0,75,75,75);
//ctx_d3.fillStyle = '#F30';
//ctx_d3.fillRect(75,75,75,75);
//ctx_d3.fillStyle = '#FFF';
//
////// 设置透明度值
////ctx_d3.globalAlpha = 0.2;
////
////// 画半透明圆
////for (var i=0;i<7;i++){
////    ctx_d3.beginPath();
////    ctx_d3.arc(75,75,10+10*i,0,Math.PI*2,true);
////    ctx_d3.fill();
////}
//// ctx_d3.fillStyle = 'rgba(255,255,255,'+(i+1)/10+')';
//  	 
//// 画半透明矩形
//for (var i=0;i<7;i++){
////  for (var j=0;j<4;j++){
//	ctx_d3.fillStyle = 'rgba(255,255,255,'+(7-i)/7+')';
//          ctx_d3.beginPath();
//    ctx_d3.arc(75,75,10+10*i,0,Math.PI*2,true);
//    ctx_d3.fill();
////  }
//}

//ctx_js.beginPath();
//ctx_js.lineCap = 'butt';
////ctx_js.lineCap = 'round';
////ctx_js.lineCap = 'square';
//ctx_js.lineWidth = 10
//ctx_js.moveTo(15.5,100)
//ctx_js.lineTo(15.5,200)
//ctx_js.stroke();
//ctx_js.beginPath();
////ctx_js.lineCap = 'butt';
//ctx_js.lineCap = 'round';
////ctx_js.lineCap = 'square';
//ctx_js.lineWidth = 9
//ctx_js.moveTo(5.5,100)
//ctx_js.lineTo(5.5,200)
//ctx_js.stroke();
//
////ctx_js.strokeStyle = 'white'
////ctx_js.lineWidth = 1;
////ctx_js.beginPath();
////ctx_js.moveTo(5.5,100);
////ctx_js.lineTo(5.5,150);
////ctx_js.stroke();
//
//
//ctx_d3.beginPath();
//ctx_d3.lineCap = 'butt';
//ctx_d3.lineWidth = 9
//ctx_d3.moveTo(15.5,100)
//ctx_d3.lineTo(15.5,200)
//ctx_d3.stroke();
//ctx_d3.beginPath();
//ctx_d3.lineCap = 'square';
//ctx_d3.lineWidth = 9
//ctx_d3.moveTo(5.5,100)
//ctx_d3.lineTo(5.5,200)
//ctx_d3.stroke();
//var offset = 5;
//
//function draw() {
//	ctx_js.clearRect(0, 0, canvasjs.width, canvasjs.height);
//	ctx_js.strokeStyle = 'black';
//	ctx_js.lineWidth = 24;
//	ctx_js.setLineDash([4, 2]);
//	ctx_js.lineDashOffset = -offset;
//	//ctx_js.strokeRect(10,10, 90, 90);
//	ctx_js.beginPath();
//	ctx_js.moveTo(10, 10);
//	ctx_js.lineTo(90, 10);
//	ctx_js.stroke();
//	ctx_js.beginPath();
//	ctx_js.strokeStyle = 'red';
//	ctx_js.lineWidth = 3;
//	ctx_js.setLineDash([12,0]);
//	ctx_js.moveTo(11.5, 10);
//	ctx_js.lineTo(11.5, 26);
//	ctx_js.stroke();
//	
//}
//
//function march() {
//	offset++;
//	if(offset > 16) {
//		offset = 0;
//	}
//	draw();
//	setTimeout(march, 5000);
//}
//
//march();
////draw();
// ctx_js.beginPath(); 
//ctx_js.arc(50, 50, 32, 0, Math.PI*2, true);
//ctx_js.arc(50, 50, 16, 0, Math.PI*2, true);
//ctx_js.arc(50, 50, 8, 0, Math.PI*2, true);
//ctx_js.fill("evenodd");
function formatDate(d) { return d.getUTCFullYear() + "-" + d.getMonth() + "-" + d.getDate(); }
      
function fetchStockHistory(symbol, months, callback) {
  var url = 'http://query.yahooapis.com/v1/public/yql';
  var endDate = new Date();
  var startDate = new Date();
  startDate.setMonth(startDate.getMonth() - months);
  var data = encodeURIComponent("select * from yahoo.finance.historicaldata where symbol in ('" 
    + symbol + "')  and startDate = '" + formatDate(startDate) + "' and endDate = '" 
    + formatDate(endDate) + "'");

  request = new XMLHttpRequest();
  request.open('GET', url+"?q="+data+"&format=json&&env=http://datatables.org/alltables.env", true);

  request.onload = function() {
    if (request.status >= 200 && request.status < 400){
      data = JSON.parse(request.responseText).query.results.quote;
      callback(data);
    }
  };

  request.send();
}